/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.posplus.losspreventiondataimporter.service;

import com.posplus.lossprevention.APDAOFactory;
import com.posplus.lossprevention.dao.ProductsDAO;
import com.posplus.lossprevention.mapping.Products;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author scottw
 */
public class ProductsService {

    private ProductsDAO productsDAO;
    
    public ProductsService(APDAOFactory lpFactory) {
        this.productsDAO = lpFactory.getProductsDAO();
    }
    
    public ProductsService(ProductsDAO productsDAO){
        this.productsDAO = productsDAO;
    }
    
    public List<Products> getAll(){
        return productsDAO.findAll();
    }

    public void bulkInsert(List<Products> mappedProducts) {
        productsDAO.bulkInsert(mappedProducts);
    }

    public void save(Products product) {
        productsDAO.makePersistent(product);
    }

    public void saveAll(List<Products> mappedProducts) {
	Iterator<Products> iter = mappedProducts.iterator();
	while (iter.hasNext()) {
	    productsDAO.save(iter.next());
	    
	}
    }
}
